﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace Soket_MMTNC_Client
{
    /// <summary>
    /// Interaction logic for Product.xaml
    /// </summary>
    public partial class Products : Window
    {
        public Products()
        {
            InitializeComponent();
            Load();
        }
        Ipserver myip = new Ipserver();
        Product bu = new Product();
        static public int id;
        public static Products me;

        public void Load()
        {
            dataGrid1.ItemsSource=bu.GetData();
        }
        private void bt_sell_Click(object sender, RoutedEventArgs e)
        {
            Product product = dataGrid1.SelectedItem as Product;
            if (product != null)
            {
                id = product.ProductID;
                Sell pw = new Sell();
                pw.ShowInTaskbar = false;
                pw.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please choose a item!", "Note", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        Product p = new Product();
        private void bt_transfer_Click(object sender, RoutedEventArgs e)
        {
            //chuyen du lieu bill den server
            //lay het cac bill co date la hom nay va gui den server
            //server se add tat ca cac bill nay vao bill.xml, voi node cha la bills, trong bill.xml
            //khong quan tam bill nay la cua client nao
            DataTable dt = p.Statistics(DateTime.Today.ToString("M/dd/yyyy"));
            if (dt.Rows.Count>0)
            {
                MainWindow.client.Send(myip.MaHoa(dt));
                MessageBox.Show("Quá trình chuyển dữ liệu đến trung tâm quản lí thành công!", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }

        private void bt_refresh_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            me = this;
        }
    }
}
